﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ConsoleApplication1.segments.field;

namespace ConsoleApplication1.segments.data_type
{
    class CM_SPS
    {
        public CE Specimen_Source_Name_Or_Code { get; set; }
        public StringBuilder Additives { get; set; }
        public StringBuilder Freetext { get; set; }
        public CE Body_Site { get; set; }
        public CE Site_Modifier { get; set; }


        public int fill(string source, int temp)
        {
            int i, x = 0;
            for (i = temp; i < source.Length; i++)
            {
                if (source[i] == '^')
                    x++;
                else if (source[i] == '|')
                {
                    Additives.Capacity = Additives.Length;
                    Freetext.Capacity = Freetext.Length;
                    return i;
                }

                else if (x == 0)
                {
                    if (Specimen_Source_Name_Or_Code == null)
                        Specimen_Source_Name_Or_Code = new CE();
                    i=Specimen_Source_Name_Or_Code.fill(source, i);
                }
                else if (x == 1)
                {
                    if (Additives == null)
                        Additives = new StringBuilder();
                    Additives.Insert(Additives.Length, source[i]);
                }
                else if (x == 2)
                {
                    if (Freetext == null)
                        Freetext = new StringBuilder();
                    Freetext.Insert(Freetext.Length, source[i]);
                }
                else if (x == 3)
                {
                    if (Body_Site == null)
                        Body_Site = new  CE();
                    i=Body_Site.fill(source, i);
                }
                else if (x == 4)
                {
                    if (Site_Modifier == null)
                        Site_Modifier = new CE();
                    i=Site_Modifier.fill(source, i);
                }               
            }
            return i;
        }
    }
}
